home *** CD-ROM | disk | FTP | other *** search
- Masterclass November
-
-
- Sometimes even AmigaDOS isn't enough - John Kennedy moves
- onto ARexx.
-
-
-
-
-
- The idea for this month's Masterclass came from a letter
- from Duncan Strand from Leicester. Duncan has several disks
- full of hundreds of sound samples, and none of them has an
- icon - which can make orginising them a bit of a problem.
-
- Duncan has been experimenting with AmigaDOS, trying to
- create multiple icons by performing variations with COPY and
- the pattern matching - none of which have worked.
-
- Now it would be possible to write an AmigaDOS script to
- create all the files, but to be honest I'm not a big fan of
- writing cumbersome programs in AmigaDOS. I know there are
- big fans out there, but I'm not one of them. When I want to
- write a program, I want to use a programming language: not
- a series of DOS commands.
-
- All Workbench 2.04 and better Amigas come with ARexx
- present. ARexx is the Amiga implementation of Rexx, a
- language which has been around for a bit. In fact, the
- alternative IBM-PC operating system, OS/2 comes with Rexx,
- although it's use is even less wide spread than the Amiga.
-
- ARexx is a little like AmigaDOS in that its programs are
- stored in plain text files, and there is no need to compile
- them first. ARexx is an interpreted language, and although
- this stops it from being the fastest language in the world,
- it also makes it one of the simpler one to use.
-
-
-
-
- Starting ARexx
- --------------
-
- Before you can use any ARexx programs, you need to make sure
- the main ARexx interpreter program is present and running.
- The name of this program is Rexxmast, and you'll find it in
- the System drawer of the Workbench drawer. You can start it
- by clicking on it, or run it from the SHELL by entering
- Rexxmast and pressing return. If you want to make it run
- automatically every time you boot your computer (which is
- especially handy if you have a hard drive, when the
- overheads will be negligible) you should add it to the file
- called 'user-startup' in the s: directory. If this file
- doesn't already exist, you can create it by entering:
-
- ed s:user-startup
-
- at the Shell. If the file does already exist it will be
- loaded, and you'll be able to add more text. In either
- case, add the following:
-
- run >nil: <nil: rexxmast
-
- The '>nil:' and '<nil' parts will ensure that a new window
- isn't opened by Rexxmast when it starts, but you can leave
- them out if you so desire. If using the standard Commodore
- ED, remember to press ESC and then X to quit.
-
-
-
- Using ARexx
- -----------
-
-
- To start an ARexx program, you use the RX command which has
- been lurking on your Workbench all this time. So to run an
- ARexx program called 'Test.rexx' (it is convention name it
- ending in .rexx') you simply open a Shell and type:
-
- rx test.rexx
-
- or
-
- rx test
-
- as it will assume the .rexx extension if it is left out.
-
- Now that's how we run a program, but how to we write one?
- In the same we used ED to alter (or create) the user-startup
- file, we also create a file containing ARexx commands. At
- this point it is worth pointing out that ED is by all
- accounts an extremely primitive text editor, and one which
- you don't have to put up with. If your finances can't
- stretch to buying Cygnus Ed (CED), you can always get GoldED
- - a superb text editor which is available from many public
- domain libraries.
-
- Writing ARexx programs isn't particularly difficult - but
- you do need to know the relevant ARexx commands.
- Unfortunately Commodore decided to cut a few costs, and
- unless you have an A4000 you probably won't have the
- necessary documentation. There are several books on the
- subject, and I recommend the Abacus guide 'Using ARexx on
- the Amiga' by Zamara and Sullivan, wholeheartedly.
-
- I've listed a few of the most important ARexx commands in
- table 1, and I hope the construction of our example program
- serves to illustrate the grammar required by ARexx.
-
- Another important point to realise is that ARexx can have
- many more commands than those in table 1. In fact, any
- program with an ARexx 'Port' will add its own commands.
-
- The Port is a special piece of programming included in the
- original program which makes available various features.
- Many commercial and public domain utilities will offer this
- facility and in this way ARexx can be used to link several
- programs together. For example, if both an image processing
- program and the software which controls a video digitiser
- have ARexx ports, it is possible to write a script that will
- get the digitiser to grab a frame and then pass it
- automatically to the image processor for further work.
- ARexx thus gives any program with a suitable port an
- extensive Macro facility and also allows it to truly make
- use of the Amiga's multitasking capabilities. Even now, the
- Mac and IBM-PC are only starting to wake up to the
- possibilities offered by such a system. The facility to
- create macros (in other words, the ability to pre-program a
- sequence of events) is terrific when a large number of
- similar operations need to be carried out.
-
- Here then is a summary of what ARexx is good at:
-
- 1. Writing small stand-alone programs,
-
- 2. Using the ARexx port present in many programs to create
- macros and automate tedious processes,
-
- 3. Linking together several separate programs, making use of
- various features from each.
-
-
-
- Writing ARexx Programs
- ----------------------
-
- The first line of an ARexx program must start with a
- comment. This isn't just a Good Idea suggested by the
- designers of Rexx, but something which has to be done or the
- program won't work. Like C, comments are contained within
- /* and */ symbols.
-
- Sometimes you'll see the ARexx word ADDRESS used. This
- specifies which other programs the ARexx system will look
- too for executing words. If, for example, you were writing
- a script that made use of ASDG's The Art Department, you
- would need to specify address 'adpro' in the ARexx program
- (the case of the port name is imporant). The only exception
- to this is when the ARexx program is executed not with the
- RX command, but from with the calling program (for example,
- Art Department) itself. It doesn't do any harm to keep the
- address line in.
-
- Using the word COMMAND after address is another exception,
- and this time instructs ARexx to use AmigaDOS functions.
-
-
- In any case, here is a small program to make sure that the
- ARexx system is working. Enter the following into a text
- file (typing it directly into the Shell will not work):
-
- /* Test program one */
-
- say "Hello, World"
-
- do 10
- say "*"
- end
-
-
-
- Now we come to creating the icons. The easiest way to do
- this is to create a dummy icon (I've called it dummy.info).
- A loop in the program then creates a host of new filenames
- using the loop counter to create the names, which will be
- sound1.info, sound2.info, sound3.info and so on. You will
- need to experiment with pathnames to suit your system.
-
-
- /* Copy program one */
-
- address command
-
- do i=1 to 10
-
- name="sound" || i || ".info"
-
- com="copy dummy.info" name
-
- com
-
- end
-
-
-
- The script is short and sweet, but it makes the assumption
- that the samples are already named sound1, sound2, sound3 to
- start with, which probably isn't the case.
-
- What we need is an ARexx program that will create an icon
- for a file of any name, and here is how to do it. First of
- all we need to rewrite the script to make use of the ARG and
- WORD command.
-
- ARG accepts a word or a list of words typed after the
- program name when it is started at the Shell. WORDS returns
- the number of separate words in a string of text, and WORD
- returns a particular word. See how simple ARexx programming
- is compared to the likes of C or BASIC?
-
- Once we have a script that will create an icon from a given
- list of files, all we need is a way to easily get the list.
- Here's the ARexx script:
-
-
- /* Copy program two */
-
- address command
-
- arg list_of_names
-
- do i=1 to words(list_of_names)
-
- name = word(list_of_names,i) || ".info"
-
- com="copy dummy.info" name
-
- com
-
- end
-
-
-
- Now to get the names of all the sound samples into a text
- file, enter this at the Shell:
-
-
- list lformat %n > ram:filelist
-
- This performs a normal directory listing, but only with the
- file names, and then redirects the list into a file in the
- ram disk.
-
- Unfortunately we can't simply run the ARexx script using
- this list, like this:
-
- rx copy.rexx <ram:filelist
-
- as the indirection doesn't seem to work. Instead we have to
- adjust the script to open up the text of the filelist
- itself. This time the script also include the necessary list
- command built-in.
-
-
-
-
-
- /* Copy program three */
-
- address command
-
- "list lformat %s >t:filelist"
-
-
- call open(filepointer,"t:filelist","r")
-
- do while ~eof(filepointer)
-
- name=readln(filepointer) || ".info"
-
- com="copy dummy.info" name
-
- com
-
- end
-
- call close (filepointer)
-
-
-
- And that's it! This script will create a temporary list of
- all the files in the T: directory, and then go through them
- one by one, copying the dummy.info icon with a new name.
- This should give all the files in the directory an icon -
- problem solved.
-
-
-
-
-
- Table 1 - Common ARexx Commands
-
-
-
-
- SAY Display text or the contents of a variable on
- screen. To see what difference quotes make,
- try the following:
-
- again=10
- say Hello World
- say "Hello, World"
- say Hello, World again
- say "Hello, World again"
-
-
-
-
-
- DO / END Packet up several lines. You can also create
- loops, like this:
-
-
- do 10
- say "Hello"
- end
-
-
- do i=1 to 10 by 2
- say i
- end
-
-
-
-
- IF THEN ELSE
-
-
- Conditional testing.
-
-
- if 1=1 then say "Phew, that was close"
-
-
- if x=19 then do
- say "Well I never"
- say "Good old X, eh?"
- end
- else
- say "too bad"
-
-
- || Concatanate two strings, without spaces.
- For example,
-
- string1 = Hello World
- string2 = Hello || World
- say string1
- say string2
-
-
-
- -----
-
- pictures: novmast1.iff
- caption: A text editor such as Cygnus Ed makes editing ARexx
- scripts so much easier than Commodore's ED.